<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Form
 *
 * @author Rymdia
 */
class Form {
    //put your code here
    //<editor-fold defaultstate="collapsed" desc="région Champs">
    private $_id = "inconnu";
    
    private $_action = "inconnu";
    
    private $_method = "POST";
    
    private $_texteHtml = "";
    
    private $_titre = "";
    
    
    // </editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="région Propriété">
    
    public function __get($propriete) {
        //get MAGIQUE avec tout les champs
        switch ($propriete) {
            case "id" : return $this->_id;
                break;
            case "action": return $this->_action;
                break;
            case "method": return $this->_method;
                break;
            case "texteHtml" : return $this->_texteHtml;
            break;
            case "titre": return $this->_titre;
                break;
            
            
        }
        }
    public function __set($propriete, $value){
        switch ($propriete) {
            case "id": $this->_id = $value;
                break;
            case "action" : $this->_action = $value;
                break;
            case "method": $this->_method = $value;
                break;
            case "texteHtml": $this->_texteHtml = $value;
                break;
            case "titre": $this->_titre =$value;
                break;
    }
    }
    
    //</editor-fold>
    
     public function __construct($id,$action,$method,$titre=null){
          $this->id = $id;
        $this->action = $action;
        $this->method = $method;

        $divTitre = ($titre==null)?"":"<div class='titre'>$titre</div>";

        $this->texteHtml .= "<form id='$id' action='$action' method='$method'></ br>$divTitre</ br>";
       
   }    
         public function __tostring(){
        return $this->texteHtml . '</form>';
    }   
    
    public function beginfieldset($class = null){
       
       $this->texteHtml.="<fieldset>";
       $testclass = ($class==null)?"":"class=".$class.">";
    }
    
    public function endfieldset(){
        $this->texteHtml.="</fieldset>";
    }   
    public function addLegend($legend){
        $this->texteHtml.="<legend>$legend</legend>";
    }
    public function AddLabelAndInput($labeltitre,$message,$type,$name,$id){
        $this->texteHtml.="<label for=".$labeltitre.">$message :</label> <input type='$type' name='$name' id='$id'/></br><span> </span>";
    }
    public function AddLabelAndCheckBox($id,$class,$type,$name,$value,$checked=null){
        if ($checked == null){
       return $this->texteHtml.="<label for=".$id." class=".$class.">".$id."</label> <input type='$type' name ='$name' value='$value'";
        }
        else{
       return $this->texteHtml.="<label for=".$id." class=".$class.">".$id."</label> <input type='$type' name ='$name' value='$value' checked='checked' ";     
        }
    }
    public function addtexte($texte,$span=null){
        if ($span==null){
            return $this->texteHtml.=$texte;
        }
        else{
            return $this->texteHtml.="<span>$texte</span>";
        }
    }
    public function br(){
        $this->texteHtml.="<br/>";
    }
    
}
